﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 社团
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            
            InitializeComponent();
        }
        public void hide()
        {
            groupBox1.Visible = false;
            groupBox2.Visible = false;
            groupBox3.Visible = false;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string Cname = textBox1.Text;
            sqlcon sqlcon=new sqlcon();
            using(SqlConnection  connection=sqlcon.connect2())
            {
                
                var query = "select*from [社团信息视图]";
                using(SqlCommand command=new SqlCommand(query,connection))
                {
                    SqlDataAdapter adapter = new SqlDataAdapter(command);
                    DataTable dataTable = new DataTable();
                    adapter.Fill(dataTable);
                    dataGridView1.DataSource = dataTable;
                }
                connection.Close();
            }
            
        }

        private void 社团信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            hide();
            groupBox1.Visible = true;
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            this.hide();
        }

        private void 社团成员信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            groupBox2.Visible = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string sno = textBox2.Text;
            string sname = textBox3.Text;
            sqlcon sqlcon = new sqlcon();
            using(SqlConnection connection=sqlcon.connect2())
            {
                var query = "select *from [社员信息视图] where 社员学号=@sno or 姓名=@sname;";
                using(SqlCommand command=new SqlCommand(query,connection))
                {
                    command.Parameters.AddWithValue("@sno", sno);
                    command.Parameters.AddWithValue("@sname", sname);
                    using(SqlDataAdapter adapter=new SqlDataAdapter(command))
                    {
                        DataTable dataTable = new DataTable();
                        adapter.Fill(dataTable);
                        dataGridView1.DataSource = dataTable;
                    }
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void 社团活动信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            groupBox3.Visible = true;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string Acname = textBox4.Text;
            string Cname = textBox5.Text;
            sqlcon sqlcon = new sqlcon();
            using(SqlConnection connection=sqlcon.connect2())
            {
                var query = "select *from [活动信息视图] where 活动名=@Acname or 负责社团=@Cname";
                using(SqlCommand command=new SqlCommand(query,connection))
                {
                    command.Parameters.AddWithValue("@Acname", Acname);
                    command.Parameters.AddWithValue("@Cname", Cname);
                    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                    {
                        DataTable dataTable = new DataTable();
                        adapter.Fill(dataTable);
                        dataGridView1.DataSource = dataTable;
                    }
                }
            }
        }
    }
}
